import { getAreaObj } from '@/utils/util'

export const formConfig = {
	inline: false,
	showBtn: true,
	labelPosition: 'right',
	labelWidth: '120px',
	column: [
		{
			label: '培训主题',
			prop: 'trainTitle',
			type: 'text',
			span: 12,
			rules: [{ required: true, message: '请输入培训主题' }],
		},
		{
			label: '培训时间',
			prop: 'trainTime',
			format: 'YYYY年MM月DD日',
			valueFormat: 'YYYY-MM-DD',
			type: 'date',
			span: 12,
			rules: [{ required: true, message: '请选择培训时间' }],
		},
		{
			label: '培训地点',
			prop: 'trainAddress',
			type: 'input',
			span: 12,
			rules: [{ required: true, message: '请输入培训地点' }],
		},
		{
			label: '培训方式',
			prop: 'trainType',
			propName: 'trainTypeLabel',
			type: 'remoteSelect',
			code: 'TRAINING_FORM',
			api: 'getDictItemList',
			filterKey: 'value',
			multiple: false,
			span: 12,
			rules: [{ required: true, message: '请选择培训方式' }],
		},
		{
			label: '培训内容',
			prop: 'trainContent',
			propName: 'trainContentLabel',
			type: 'remoteSelect',
			code: 'AM_TRAIN_CONTENT',
			api: 'getDictItemList',
			filterKey: 'value',
			multiple: false,
			span: 12,
			rules: [{ required: true, message: '请选择培训内容' }],
		},
		{
			label: '培训参与人员',
			prop: 'trainParticipants',
			type: 'textarea',
			span: 12,
			rules: [{ required: true, message: '请输入培训参与人员' }],
		},
		{
			label: '培训照片',
			prop: 'trainPhoto',
			type: 'upload',
			listType: 'picture-card',
			labelPosition: 'top',
			showFileList: true,
			limit: 4,
			multiple: true,
			changeField: true,
			span: 12,
			rules: [{ required: true, message: '请上传培训照片' }],
		},
		{
			label: '培训签到表',
			prop: 'trainSign',
			type: 'upload',
			listType: 'picture-card',
			labelPosition: 'top',
			showFileList: true,
			limit: 4,
			multiple: true,
			changeField: true,
			span: 12,
		},
	],
}

export const searchConfig = {
	inline: true,
	showBtn: true,
	labelPosition: 'left',
	column: [
		{
			label: '所属地区',
			prop: 'areas',
			type: 'AplidAreaSelect',
			span: 8,
		},
		{
			label: '培训主题',
			prop: 'trainTitle',
			type: 'input',
			span: 8,
		},
		{
			label: '培训方式',
			prop: 'trainType',
			propName: 'trainTypeLabel',
			type: 'remoteSelect',
			code: 'TRAINING_FORM',
			api: 'getDictItemList',
			filterKey: 'value',
			multiple: false,
			span: 8,
		},
		{
			label: '培训内容',
			prop: 'trainContent',
			propName: 'trainContentLabel',
			type: 'remoteSelect',
			code: 'AM_TRAIN_CONTENT',
			api: 'getDictItemList',
			filterKey: 'value',
			multiple: false,
			span: 8,
		},
		{
			label: '培训时间',
			prop: 'trainTimeBetween',
			format: 'YYYY年MM月DD日 HH:mm:ss',
			valueFormat: 'YYYY-MM-DD HH:mm:ss',
			type: 'dateBetween',
			span: 8,
		},
	],
}

export const tableConfig = {
	stripe: true,
	border: true,
	columns: [
		{ label: '所属区域', prop: 'beAreaNames' },
		{ label: '培训主题', prop: 'trainTitle' },
		{ label: '培训时间', prop: 'trainTime' },
		{ label: '培训地点', prop: 'trainAddress' },
		{ label: '培训方式', prop: 'trainTypeLabel' },
		{ label: '培训内容', prop: 'trainContentLabel' },
		{ label: '培训参与人员', prop: 'trainParticipants' },
		{
			label: '培训照片',
			custome: 'file',
			prop: 'trainPhoto',
		},
		{
			label: '操作',
			prop: 'menu',
			width: 300,
			fixed: 'right',
		},
	],
}

export const api = {
	index: 'view_amTrainRecord_page',
	add: 'view_amTrainRecord_add',
	edit: 'view_amTrainRecord_edit',
	delete: 'view_amTrainRecord_del',
	detail: 'view_amTrainRecord_view',
	export: 'view_amTrainRecord_export',
}
export const auth = {
	...api,
}
export const baseConfig = {
	pageName: '银发顾问培训记录',
	dictcodes: ['TRAINING_FORM', 'AM_TRAIN_CONTENT'],
	rowKey: 'id',
	addLabel: '新增',
	tipLabel: 'trainTitle',
	exportMqTopic: '/ning/export/',
	api,
	auth,
	menuBtn: [
		{
			icon: 'editor',
			label: '编辑',
			type: 'primary',
			operate: 'edit',
			auth: auth.edit,
			text: true,
			show: true,
		},
		{
			icon: 'delete',
			label: '删除',
			type: 'danger',
			operate: 'delete',
			auth: auth.delete,
			text: true,
			show: true,
		},
		{
			icon: 'detail',
			label: '详情',
			type: 'primary',
			operate: 'detail',
			auth: auth.index,
			text: true,
			show: true,
		},
	],

	saveFormate: async (form) => {
		return new Promise((resolve, reject) => {
			resolve(form)
		})
	},
	beforeOnLoadFormate: async (query) => {
		return new Promise((resolve, reject) => {
			const areasObj: any = getAreaObj(query.areas, 'be')
			resolve({
				...query,
				...areasObj,
				areas: undefined,
			})
		})
	},
	onLoadFormate: async (arr) => {
		return new Promise((resolve, reject) => {
			resolve(
				arr.map((item) => {
					const beAreaNames = getAreaObj(item, 'be')
					return {
						...item,
						beAreaNames,
					}
				})
			)
		})
	},
	dialogConfig: {
		width: '75%',
	},
	searchConfig,
	formConfig,
	tableConfig,
	detailConfig: formConfig,
}
